package net.qiqb.ddd.user.infrastructure;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.domain.annotation.AggregateLoader;
import net.qiqb.core.domain.annotation.BusinessIdMapping;
import net.qiqb.core.domain.annotation.LoadAggregateRoot;
import net.qiqb.ddd.user.domain.UserAggregateRoot;
import net.qiqb.execute.UserId;

@Slf4j
@AggregateLoader
public class UserLoaders {

    @LoadAggregateRoot
    public UserAggregateRoot loadById(@BusinessIdMapping("id") UserId userId) {
        log.info("根据 id 加载用户对象");
        return new UserAggregateRoot(userId, "张三");
    }

    @LoadAggregateRoot
    public UserAggregateRoot loadByMobile(@BusinessIdMapping("mobile") String account) {
        log.info("根据 mobile 加载用户对象");
        return new UserAggregateRoot(new UserId(account), "张三");
    }

    @LoadAggregateRoot
    public UserAggregateRoot loadByName(@BusinessIdMapping("account") String account) {
        log.info("根据 account 加载用户对象");
        return new UserAggregateRoot(new UserId(account), "张三");
    }
}
